package freeboard.model.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import freeboard.dto.FreeBoardDTO;

public class FreeBoardDAO {
	private SqlMapClientTemplate sqlMap;
	public FreeBoardDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	public int selectBoardNo() throws SQLException {
		return (Integer) sqlMap.queryForObject("freeboard.selectBoardNo");
	}
	
	public void insertContent(FreeBoardDTO fdto)throws SQLException{
		sqlMap.insert("freeboard.insertContent", fdto);
	}
	public int selectTotalContent() throws SQLException {
		return (Integer) sqlMap.queryForObject("freeboard.selectTotalContent");
	}
	
	public ArrayList<FreeBoardDTO> selectBoardListByPage(int page,int a) throws SQLException {
		HashMap map = new HashMap();
		map.put("page", page);
		map.put("a", a);
		return (ArrayList<FreeBoardDTO>) sqlMap.queryForList("freeboard.selectBoardListByPage",map);
	}
	public void updateViewcount(int no) throws SQLException {
		this.sqlMap.update("freeboard.updateViewcount",no);
	}
	public FreeBoardDTO selectContentByNO(int no) throws SQLException {
		return (FreeBoardDTO) this.sqlMap.queryForObject("freeboard.selectContentByNO",no);
	}
	public FreeBoardDTO getNext(int no) throws SQLException {
		return (FreeBoardDTO) this.sqlMap.queryForObject("freeboard.getNext",no);
	}

	public FreeBoardDTO getPrev(int no) throws SQLException {
		return (FreeBoardDTO) this.sqlMap.queryForObject("freeboard.getPrev",no);
	}
}
